﻿namespace XYAC.Framework.WohuaMesExtend.IHI.Extensions
{
    public struct Crc128
    {
        public ulong High;
        public ulong Low;
        /// <summary>
        /// 将 Crc128 转换为字符串表示
        /// </summary>
        /// <returns></returns>
        public override string ToString()
        {
            return $"{High:X16}{Low:X16}";
        }

        /// <summary>
        /// 从字符串转换回 Crc128 结构体
        /// </summary>
        /// <param name="crcString"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public static Crc128 FromString(string crcString)
        {
            if (crcString.Length != 32)
            {
                throw new ArgumentException("Invalid CRC128 string length.");
            }

            ulong high = ulong.Parse(crcString.Substring(0, 16), System.Globalization.NumberStyles.HexNumber);
            ulong low = ulong.Parse(crcString.Substring(16, 16), System.Globalization.NumberStyles.HexNumber);

            return new Crc128 { High = high, Low = low };
        }
    }

}
